<template>
	<div class="allcontainer" v-loading="loading">
		<div class="h2">{{ $route.query.Name }}全部活动</div>
		<div class="bg-white">
		<div id="components-form-demo-advanced-search">
			<a-form class="ant-advanced-search-form home-form" :form="form" @submit="handleSearch">
				<a-row :gutter="24">
					<a-col :span="8">
						<a-form-item label="名称">
							<a-input class="field-right" placeholder="请输入名称搜索" v-decorator="[`key`]" />
						</a-form-item>
					</a-col>
					<a-col :span="8" class="option">
						<a-button type="primary" html-type="submit" class="btn1">搜索</a-button>
						<a-button @click="handleReset" class="btn2">重置</a-button>
					</a-col>
				</a-row>
			</a-form>
		</div>
		<div class="table">
			<el-table  stripe ref="singleTable" :data="data" highlight-current-row style="width: 100%">
				<el-table-column prop="No" label="编号" width="120" fixed="left" align="center"></el-table-column>
				<el-table-column prop="Title" label="名称" min-width="100" fixed="left"></el-table-column>
				<el-table-column prop="TypeName" label="类型" min-width="120" show-overflow-tooltip align="center"></el-table-column>
				<el-table-column prop="ChargeUserName" label="主席" min-width="140" align="center"></el-table-column>
				<el-table-column prop="ChargeUserNo" label="学号" min-width="140" align="center"></el-table-column>
				<el-table-column prop="AddTime" label="活动时间" min-width="120" align="center">
					<template slot-scope="scope">
						<div>始：{{ scope.row.StartTime }}</div>
						<div>终：{{ scope.row.EndTime }}</div>
					</template>
				</el-table-column>
				<el-table-column prop="IsEnable" label="操作" width="145">
					<template slot-scope="scope">
						<div class="user-btn user-btn-auto" v-if="new Date().getTime() < new Date(scope.row.EndTime.replace(/-/g, '/')).getTime()">
							<span class="join" v-if="scope.row.State != 5" @click="JoinActivity(scope.row)">申请加入活动</span>
						</div>
					</template>
				</el-table-column>
			</el-table>

			<el-pagination
				@size-change="handleSizeChange"
				@current-change="handleCurrentChange"
				:current-page="pagination.currentPage"
				:page-sizes="pagination.pageSizeOptions"
				:page-size="pagination.pageSize"
				layout="total, sizes, prev, pager, next, jumper"
				:total="pagination.total"
			></el-pagination>
		</div>
		</div>
		<applyActivity :approvalType="4" :text="text" v-show="showModal" @closeFun="closeFun(1)"></applyActivity>
	</div>
</template>

<script>
import Func from '@/utils/func';
import { GetActivityPageList, GetActivityStateList } from '@/api/follow';
import applyActivity from '@/components/ApplyActivity';
const data = [];
export default {
	components: {
		applyActivity
	},
	props: {
		// text: Object,
		type: Number
	},
	data() {
		return {
			data,
			form: this.$form.createForm(this, {
				name: 'advanced_search'
			}),
			pagination: {
				currentPage: 1,
				pageSize: this.global.pageSize,
				pageSizeOptions: this.global.pageSizeOptions, // 每页中显示的数据
				showTotal: total => `共有 ${total} 条数据` // 分页中显示总的数据
			},
			TypeList: [
				{
					ID: 'null',
					Name: '待审核'
				},
				{
					ID: 'true',
					Name: '审核通过'
				},
				{
					ID: 'false',
					Name: '审核未通过'
				}
			],
			addIf: false,
			visible: false,
			confirmLoading: false,
			itemId: '',
			departmentList: [],
			worklist: [],
			loading: false,
			values: {},
			pages: {
				pageIndex: 1,
				pageSize: 20
			},
			tableHeight: parseFloat(window.innerHeight - 160),
			TypeIDList: [],
			DepartCodeList: [],
			ProjectIDList: [],
			ishaveid: true,
			selectList: {},
			showModal: false,
			ClubID: this.$route.query.ID,
			ActivityStateList: [],
			time: '',
			requestUrl: this.global.requestUrl,
			text: {}
		};
	},
	computed: {},
	created() {
		this.getList();
		this.ActivityState();
	},
	mounted() {},
	methods: {
		async ActivityState() {
			let res = await GetActivityStateList();
			this.ActivityStateList = res.data.data;
		},
		applydelete(text) {
			// this.visible = true
			// this.deletelist = text
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定删除该申请吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await UserdeleteActivity(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		sumbitapply(text) {
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定提交活动审批吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await UserSubmitActivity(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		callback(key) {
			this.getList(key);
		},
		handleChange(val) {
			this.currentRow = val;
			if (val.ID) {
				this.ishaveid = false;
				this.selectList = val;
			} else {
				this.ishaveid = true;
			}
		},
		handleSearch(e) {
			e.preventDefault();
			this.form.validateFields((error, values) => {
				this.pagination.currentPage = 1;
				this.values = values;
				this.getList();
			});
		},
		handleReset() {
			this.form.resetFields();
			this.values = {};
			this.getList();
		},
		handleSizeChange(val) {
			this.pagination.pageSize = val;
			this.getList();
		},
		handleCurrentChange(val) {
			this.pagination.currentPage = val;
			this.getList();
		},
		async getList(key) {
			this.loading = true;
			let data = {};
			if (this.values) {
				data = this.values;
			}

			data.pageIndex = this.pagination.currentPage;
			data.pageSize = this.pagination.pageSize;
			data.clubID = this.$route.query.ID;
			let res = await GetActivityPageList(data);

			this.data = res.data.data;
			this.loading = false;
			const pagination = { ...this.pagination };
			pagination.total = res.data.pageInfo.TotalItemCount;
			this.pagination = pagination;
		},
		addActivity(t, type) {
			this.type = type;
			this.text = { ...t, time: new Date() };
			this.showModal = !this.showModal;
		},
		JoinActivity(t) {
			this.text = { ...t, time: new Date() };
			this.showModal = !this.showModal;
		},
		modifyList(text) {
			// text = Object.assign(text, {
			// 	time: new Date()
			// });
			this.showModal = !this.showModal;
			this.text = text;
		},
		enableList(text) {
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定要${text.IsEnable ? '停用' : '启用'}该学生组织吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await EnableClub(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		deleteList(text) {
			let that = this;
			this.$confirm({
				title: '提示',
				content: `您确定删除该学生组织吗？`,
				okText: '确认',
				cancelText: '取消',
				async onOk() {
					let data = {};
					data.id = text.ID;
					let res = await DeleteClub(data);
					if (res.data.code == 0) {
						that.getList();
						that.$message.success(res.data.msg);
					} else {
						that.$message.error(res.data.msg);
					}
				}
			});
		},
		seeList(text, name) {
			let path = '';
			if (name == 'teacher') {
				path = 'ClubTeacher';
			} else if (name == 'manage') {
				path = 'ClubManagerList';
			} else {
				path = 'ClubMember';
			}
			this.$router.push({
				name: path,
				query: {
					ID: text.ID
				}
			});
		},
		closeFun(index) {
			this.showModal = false;
			this.detailshowModal = false;
			this.updateshowModal = false;
			this.getList();
		}
	}
};
</script>

